#!/bin/bash

sudo pacman -S nvidia-dkms nvidia-settings nvidia-prime nvidia-utils


sudo sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/ s!"$! nvidia_drm.modeset=1"!' /etc/default/grub

sudo sed -i '/^HOOKS=/s/\bkms\b//g' /etc/mkinitcpio.conf

sudo sed -i '/^MODULES=/ s/)/ nvidia nvidia_modeset nvidia_uvm nvidia_drm)/' /etc/mkinitcpio.conf

#mkinitpio might auto build kernel after nvidia update~

#sudo mkdir /etc/pacman.d/hooks
#sudo cp ./nvidia.hook /etc/pacman.d/hooks/

echo -e "do you want to intel graphic first ? (power-save and load nvidia if need)\n1.intel 2.nvidia"
read save
if [ $save -eq 2 ];then
sudo cp  -f ./99-gpu-nvidia_prefer.conf /etc/X11/xorg.conf.d/99-gpu.conf
else
sudo cp  -f ./99-gpu.conf /etc/X11/xorg.conf.d/99-gpu.conf
fi



#cp .xinitrc ~/


echo "more info visit https://zhuanlan.zhihu.com/p/568981775?utm_id=0 "
